#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

int main() {
    std::vector<int> primeNumbers;
    for (int i = 2; i < 1000; i++) {
        int isPrime = 1;
        for (int j = 2; j < i / 2; j++) {
            if (i % j == 0) {
                isPrime = 0;
                break;
            }
        }
        if (isPrime) {
            primeNumbers.push_back(i);
        }
    }

    std::vector<std::string> num = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    std::string input;
    std::getline(std::cin, input);
    std::replace(input.begin(), input.end(), '9', '&');
    std::replace(input.begin(), input.end(), '8', '&');
    std::replace(input.begin(), input.end(), '7', '&');
    std::replace(input.begin(), input.end(), '6', '&');
    std::replace(input.begin(), input.end(), '5', '&');
    std::replace(input.begin(), input.end(), '4', '&');
    std::replace(input.begin(), input.end(), '3', '&');
    std::replace(input.begin(), input.end(), '2', '&');
    std::replace(input.begin(), input.end(), '1', '&');
    std::replace(input.begin(), input.end(), '0', '&');

    if (input.find('&') != std::string::npos || input.empty() || std::count(input.begin(), input.end(), ' ') != 2) {
        std::cout << "Wrong input" << std::endl;
    } else {
        std::vector<std::string> data;
        size_t pos = 0;
        while ((pos = input.find(' ')) != std::string::npos) {
            data.push_back(input.substr(0, pos));
            input.erase(0, pos + 1);
        }

        std::string newStr = "";
        for (const auto &i : data) {
            newStr += std::to_string(std::distance(num.begin(), std::find(num.begin(), num.end(), i)));
        }
        int n = std::stoi(newStr);

        std::vector<std::pair<int, int>> result;
        for (const auto &i : primeNumbers) {
            result.push_back(std::make_pair(std::abs(n - i), i));
        }

        std::sort(result.begin(), result.end());
        std::cout << result[0].second << std::endl;
    }

    return 0;
}
